package com.xieyong.leetcode;

import java.util.stream.IntStream;

public class Leetcode2419 {

    public static void main(String[] args) {
        Leetcode2419 leetcode2419 = new Leetcode2419();
        int[] nums = {1, 2, 3};
        int i = leetcode2419.longestSubarray(nums);
        System.out.println(i);
    }

    public int longestSubarray(int[] nums) {
        // 就是找最大数最长相同的子数组
        int max = IntStream.of(nums).max().getAsInt(), res = 1;
        for (int i = 0, l = -1, r = -1; i < nums.length; i++) {
            if (nums[i] == max) {
                r = i;
                res = Math.max(res, r - l);
            } else {
                l = i;
            }
        }
        return res;
    }
}
